home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
stdio
/
RCS
/
fgets.c,v
< prev
next >
Wrap
Text File
|
1992-01-21
|
3KB
|
133 lines
head 1.2;
branch ;
access ;
symbols sprited:1.1.1;
locks ; strict;
comment @ * @;
1.2
date 92.01.21.16.29.07; author shirriff; state Exp;
branches ;
next 1.1;
1.1
date 88.06.10.16.23.44; author ouster; state Exp;
branches 1.1.1.1;
next ;
1.1.1.1
date 91.12.02.19.56.13; author kupfer; state Exp;
branches ;
next ;
desc
@@
1.2
log
@Made a change to behavior if nothing read, to make it compatible
with Unix.
@
text
@/*
* fgets.c --
*
* Source code for the "fgets" library procedure.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/fgets.c,v 1.1 88/06/10 16:23:44 ouster Exp Locker: shirriff $ SPRITE (Berkeley)";
#endif not lint
#include "stdio.h"
/*
*----------------------------------------------------------------------
*
* fgets --
*
* Reads a line from a stream.
*
* Results:
* Characters are read from stream and placed at buf until a
* newline is encountered or maxChars-1 characters have been
* processed or an end of file or error is encountered. The
* string at buf is left null-terminated. The return value is
* a pointer to buf if all went well, or NULL if an end of file
* or error was encountered before reading any characters.
*
* Side effects:
* Characters are removed from stream.
*
*----------------------------------------------------------------------
*/
char *
fgets(bufferPtr, maxChars, stream)
char *bufferPtr; /* Where to place characters. Must have
* at least maxChars bytes of storage. */
register int maxChars; /* Maximum number of characters to read
* from stream. */
register FILE *stream; /* Stream from which to read characters. */
{
register char *destPtr = bufferPtr;
register int c;
for (maxChars--; maxChars > 0; maxChars--) {
c = getc(stream);
if (c < 0) {
/* Other systems don't clear destPtr, and it breaks some programs,
* so I'm taking this out.
*/
#if 0
*destPtr = 0;
#endif
return NULL;
}
*destPtr = c;
destPtr++;
if (c == '\n') {
break;
}
}
*destPtr = 0;
return bufferPtr;
}
@
1.1
log
@Initial revision
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: atoi.c,v 1.1 88/04/28 17:20:23 ouster Exp $ SPRITE (Berkeley)";
d57 4
d62 1
@
1.1.1.1
log
@Initial branch for Sprite server.
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/fgets.c,v 1.1 88/06/10 16:23:44 ouster Exp $ SPRITE (Berkeley)";
@